#encoding:UTF-8
import re
import mylib
import pythonlibSB


def get_hot_link():
    try:
        results = []
        
        content = mylib.get_content('http://tiin.vn/')
        
        hot_10_link = []
        hot_10_content = pythonlibSB.s_string(content,'class="tin-tieu-diem"','li')
#        print hot_10_content
        reg = re.compile('(<a)(.*?)(href=")(.*?)(")(.*?)(<img)')
        if reg.search(hot_10_content):
            url10 = reg.search(hot_10_content).group(4)
            url10 = url10 if url10.find('http://')!=-1 else ('http://tiin.vn'+url10)
            hot_10_link.append(url10)
        results.append(hot_10_link)
        
        hot_left_link = []
        hot_left_content = pythonlibSB.s_string(content,'class="top_left_main"','div')
        for i in re.finditer('(<a)(.*?)(href=")(.*?)(")(.*?)("><img)',hot_left_content):
            url9 = i.group(4) if i.group(4).find('http://')!=-1 else ('http://tiin.vn'+i.group(4))
            hot_left_link.append(url9)
        
        hot_9_link = []
        hot_9_content = pythonlibSB.s_string(content,'class="slide_bt"','div')
        for j in re.finditer('(<a)(.*?)(href=")(.*?)(")(.*?)("><img)',hot_9_content):
            url92 = j.group(4) if j.group(4).find('http://')!=-1 else ('http://tiin.vn'+j.group(4))
            hot_9_link.append(url92)
        hot_9_link = hot_9_link + hot_left_link
        results.append(hot_9_link)
        
        
        hot_8_link = []
        hot_8_content = pythonlibSB.s_string(content,'class="right_hot_news_main"','div')
        for k in re.finditer('(<a)(.*?)(href=")(.*?)(")',hot_8_content):
            url8 = k.group(4) if k.group(4).find('http://')!=-1 else ('http://tiin.vn'+k.group(4))
            hot_8_link.append(url8)
        results.append(hot_8_link)
        
        
        hot_7_link = []

        
        results.append(hot_7_link)
        
        return results
    except:
        return []
    
if __name__ == "__main__":
    
    results = get_hot_link()
    print results